﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using IniParser;
//using Installer;

namespace Installer
{
    public class InstallerAPI
    {
        private RunInstallers _runinstallers;

        public InstallerAPI()
        {
            SetOptions();
            _runinstallers = new RunInstallers();
        }

        private void SetOptions()
        {
            if (CheckGroup())
            {
                IniHandler.IniOptions.Instance.SetIniFile(Installer.Properties.Settings.Default.LocationStaffSoftwareIni);
            }
            else
            {
                IniHandler.IniOptions.Instance.SetIniFile(Installer.Properties.Settings.Default.LocationStudentSoftwareIni);
            }
        }
        
        private bool CheckGroup()
        {
            ActiveDirectory.GroupCheck CheckGroupUser = new ActiveDirectory.GroupCheck();
            string UserName = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
            string Domain = WindowsIdentity.GetCurrent().Name.Split('\\')[0];
            string Group = Installer.Properties.Settings.Default.SchoolCode + "gg_usrstaff";
            return CheckGroupUser.Check_If_Member_Of_AD_Group(UserName, Domain, Group);
        }

        public SectionDataCollection GetSections()
        {
            return IniHandler.IniOptions.Instance.GetSection();
        }

        public void InstallSoftware(List<string> Toinstall)
        {

            _runinstallers.RunAllInstallers(Toinstall);
        }


        public string GetCurrentInstalling()
        {
            return _runinstallers.GetCurrent();
        }
    }


}
